

<script src="__TMPL__/public/assets/js/jquery-1.10.2.min.js"></script>
<script src="__TMPL__/public/assets/layui/layui.js"></script>
<script src="__STATIC__/js/laydate.js"></script>
<link  href="__TMPL__/public/assets/layui/css/layui.css" rel="stylesheet">
<script src="__STATIC__/js/echarts.min.js"></script>

<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#test5' //指定元素
        });
    });
</script>


<form class="layui-form" action="" style="display: flex;padding-top: 20px">
    <div class="layui-form-item">
        <label class="layui-form-label">产品名称</label>
        <div class="layui-input-block">
            <input type="text" id="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="start_time" id="test5" placeholder="yyyy-MM-dd ">
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-block">
            <select name="interest" id="status" lay-filter="aihao">
                <option value=''>全部</option>
                <option value='1'>报单中</option>
                <option value='2'>已完成</option>
                <option value='3'>已取货</option>
                <option value='4'>已结款</option>
                <option value='5'>已核查</option>
            </select>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit="" id="selectval" lay-filter="demo1">查看</button>
            <a href="" class="layui-btn ">重置</a>
        </div>
    </div>
</form>

<table class="table table-hover table-bordered">

    <table class="layui-hide" id="test" lay-filter="test"></table>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <!--                <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>-->
            <!--                <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
            <!--                <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
        </div>
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="list">查看订单</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <script type="text/html" id="barDemo1">
        <a class="" title="填写快递单" lay-event="sendmsg1">
            <i class="layui-icon layui-icon-release"></i>
        </a>
        <a class="" title="填写转寄单" lay-event="sendmsg2">
            <i class="layui-icon layui-icon-release"></i>
        </a>

    </script>

    <!--    自定义    -->
    <script type="text/html" id="titleTpl">
        {{#  if(d.types ==1 ){ }} 酒类 {{#  } }}
        {{#  if(d.types ==2 ){ }} 手机 {{#  } }}
        {{#  if(d.types ==3 ){ }} 其他 {{#  } }}
    </script>

    <!--    自定义    -->
    <script type="text/html" id="titleTpl1">
        {{#  if(d.status ==1 ){ }} 报单中 {{#  } }}
        {{#  if(d.status ==2 ){ }} 已完成 {{#  } }}
        {{#  if(d.status ==3 ){ }} 已取货 {{#  } }}
        {{#  if(d.status ==4 ){ }} 已结款 {{#  } }}
        {{#  if(d.status ==5 ){ }} 已核查 {{#  } }}

    </script>
    <script>

        layui.use(['table','form','laydate'], function(){
            var table = layui.table,form = layui.form,laydate=layui.laydate;
            var curl="{:url('order/getlist')}";

            var tableIns =table.render({
                elem: '#test' ,
                url:curl,
                method: 'post',
                toolbar: '#toolbarDemo',
                title: '用户数据表',
                cols: [[

                    {field:'id', title:'ID', width:80}
                    ,{field:'title', title:'名称',edit: 'text'}
                    ,{field:'desc', title:'全部商品',edit: 'text'}
                    ,{field:'types', title:'类型', templet: '#titleTpl'}
                    ,{field:'status', title:'状态', templet: '#titleTpl1'}
                    ,{field:'from', title:'创建'}
                    ,{field:'endtime', title:'截至时间'}
                    ,{field:'tip', title:'提醒', toolbar: '#barDemo1', width:100}
                    ,{fixed: 'right', title:'操 作', toolbar: '#barDemo',width: 220}
                ]]
                ,page: true
            });


            $("#selectval").click(function (){

                var start_time=$("#test5").val();
                var title=$("#title").val();
                var status=$("#status").val();
                console.log(start_time,title,status)

                tableIns.reload({
                    where: { start_time:start_time ,title:title,status:status} ,
                    page: { curr: 1  }
                });

            })

            //表格工具行事件
            table.on('tool(test)', function(obj){
                var data = obj.data;
                //console.log(obj)

                if(obj.event === 'sendmsg1'){

                    var curl="{:url('order/msge1')}";
                    layer.msg('发送中。。。')
                    $.ajax({
                        url: curl,
                        data:{'id':data.id},
                        type:'post',
                        success:function (ret){
                            layer.msg(ret.msg)
                        }
                    })
                }

                if(obj.event === 'sendmsg2'){

                    var curl="{:url('order/msge2')}?id="+data.id;
                    layer.msg('发送中。。。')
                    $.ajax({
                        url: curl,
                        data:{'id':data.id},
                        type:'post',
                        success:function (ret){
                            layer.msg(ret.msg)
                        }
                    })
                }


                if(obj.event === 'del'){

                    var curl="{:url('order/delete')}";

                    layer.confirm('真的删除行么', function(index){
                        $.ajax({
                            url: curl,
                            data:{'id':data.id},
                            type:'post',
                            success:function (ret){
                                layer.msg(ret.msg);

                                if (ret.code==1){
                                    obj.del();
                                    layer.close(index);
                                }

                            }
                        })


                    });
                } else if(obj.event === 'edit'){

                    var curl="{:url('order/edit')}?id="+data.id;

                    layer.open({
                        type: 2,
                        area: ['700px', '500px'],
                        content: curl,
                        success:function (){
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        }
                    });
                }else if(obj.event === 'list'){

                    var curl="{:url('order/seeorder')}?id="+data.id;

                    layer.open({
                        type: 2,
                        area: ['1300px', '800px'],
                        offset:['10px','10px'],
                        content: curl,
                        success:function (){

                        }
                    });
                }
            });


            form.render();


        });
    </script>


</table>